<?php
namespace app\index\controller;

use app\index\model\Users;
use think\admin\Controller;

class Base extends Controller
{

    protected $uid;
    protected $user_info;

    public function initialize()
    {
      $this->check_login();
      $userID = $this->app->session->get('uid');
      if($userID){
        $this->uid = $userID;
        $userInfo = Users::with(['role'])->where('id',$userID)->find();
        $this->user_info = $userInfo;
        $this->assign('userInfo',$userInfo);
        $this->assign('role',$this->user_info->role);
      }
      $this->assign('is_login', (isset($userID) && $userID > 0) ? true : false);
      $this->assign('controller', strtolower(request()->controller()));
      $this->assign('action', strtolower(request()->action()));
      $this->assign('config',sysconf());
      $this->assign('c_ip',get_real_ip());
    }

    /**
     * @name:检查登录
     * @author:Sam
     * @date:2024-09-02
     * @param:[string] param [desc]
    */
    public function  check_login(){
      $userID = $this->app->session->get('uid');
      if(empty($userID)){
        return $this->redirect('/login');
      }
    }
}
